home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / tos.arc / keytbl.c < prev    next >
C/C++ Source or Header  |  1989-09-03  |  2KB  |  127 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <tos.h>
  4.  
  5. #define SUCCESS 0
  6. #define FAILURE 1
  7.  
  8. void put(unsigned char * ptr, char * comment, char * name);
  9. void putone(unsigned char ch);
  10.  
  11. char * comments[] =
  12. {
  13.     "unshifted", "shifted", "capslocked"
  14. };
  15.  
  16. char * names[] =
  17. {
  18.     "keynorm", "keyshft", "keycaps"
  19. };
  20.  
  21. FILE * fdes;
  22.  
  23. void main(int argc, char * argv[])
  24. {
  25.     register i;
  26.     unsigned char ** tostbl;
  27.     char * def_tbl = (char *) -1L;
  28.  
  29.     fdes = stdout;
  30.     if (--argc)
  31.     {
  32.         if ((fdes = fopen(*++argv, "w")) == (FILE *) 0)
  33.         {
  34.             fprintf(stderr, "can't open output file %s\n", *argv);
  35.             exit(FAILURE);
  36.         }
  37.     }
  38.  
  39.     /*
  40.      * fetch pointer to table of 3 pointers to TOS tables
  41.      */
  42.     tostbl = (unsigned char **) Keytbl(def_tbl, def_tbl, def_tbl);
  43.  
  44.     /*
  45.      * sanity
  46.      */
  47.     for (i = 0; i < 3; i++)
  48.     {
  49.         if (tostbl[i][1] != 033)
  50.         {
  51.             fprintf(stderr, "bad TOS table[%d]\n", i);
  52. #ifdef USE_DESKTOP
  53.             getchar();
  54. #endif
  55.             exit(1);
  56.         }
  57.     }
  58.  
  59.     /* some lines comment */
  60.     fprintf(fdes, 
  61.         "/* %s: contains the current key maps retrieved\n", *argv);
  62.     fprintf(fdes, " * from the TOS environment.\n");
  63.     fprintf(fdes, " * Use in the directory 'kernel'\n */\n\n");
  64.  
  65.     /*
  66.      * copy each of the three tables into stdout or header file.
  67.      */
  68.     for (i = 0; i < 3; i++)
  69.         put(tostbl[i], comments[i], names[i]);
  70.  
  71.     exit(SUCCESS);
  72. }
  73.  
  74. void put(unsigned char * ptr, char * comment, char * name)
  75. {
  76.     int i;
  77.     int j;
  78.  
  79.     fprintf(fdes, "/* Scan codes to ASCII for %s keys */\n", comment);
  80.     fprintf(fdes, "PUBLIC unsigned char %s[] = {\n", name);
  81.  
  82.     for (i=0; i < 16; i++)
  83.     {
  84.         fprintf(fdes, "/*%02x*/   ", i*8);
  85.         for (j=0; j<8; j++)
  86.             putone(ptr[i*8+j]);
  87.         fprintf(fdes, "\n");
  88.     }
  89.     fprintf(fdes, "};\n\n");
  90. }
  91.  
  92. void putone(unsigned char ch)
  93. {
  94.     switch (ch)
  95.     {
  96.     case '\'':
  97.         fprintf(fdes, " '\\'',");
  98.         break;
  99.  
  100.     case '\\':
  101.         fprintf(fdes, " '\\\\',");
  102.         break;
  103.  
  104.     case '\b':
  105.         fprintf(fdes, " '\\b',");
  106.         break;
  107.  
  108.     case '\r':
  109.         fprintf(fdes, " '\\r',");
  110.         break;
  111.  
  112.     case '\t':
  113.         fprintf(fdes, " '\\t',");
  114.         break;
  115.  
  116.     case 0x9c:
  117.         fprintf(fdes, "  '@',");
  118.         break;
  119.  
  120.     default:
  121.         if ((ch > 0x1f) && (ch < 0x7f))
  122.             fprintf(fdes, "  '%c',", ch);
  123.         else
  124.             fprintf(fdes, " 0x%02X,", (unsigned char) ch);
  125.     }
  126. }
  127.